import { getUserInfo } from "@/api/index";

export default {
  state: {
    userinfo: {},
    user: {},
    token: "",
    roles:[],
    equipment:{},
    equipmentName:'',
    equipmentId:null
  },
  getters: {},
  mutations: {
    USERfun(state, value) {
      state.equipment = value;
      state.equipmentName= value.equipmentName
      state.equipmentId= value.equipmentId
    },
    SET_USERINFO: (state, res) => {

        //state.userinfo = res
        state.user= res.user
        state.roles= res.roles
    },
    SET_TOKEN: (state, token) => {
      state.token_001 = token
      state.token = token
    },
    LOGOUT: (state) =>{
      state.token = ""
      state.user={}
      state.roles=[]
    },
  },
  actions: {
    asyncuserefunction({ commit }, value) {
      commit("USERfun", value);
    },
    async loadUserInfo({ commit }, token) {
      commit("SET_TOKEN", token);
      let res = await getUserInfo();
      console.log(res)
      return commit("SET_USERINFO", res);
    },
  },
  modules: {},
  namespaced: true,
};
